package com.fly.glide;

import android.content.Context;
import android.graphics.Bitmap;

import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;

/**
 * Created with Android Studio.
 * Package_Name：com.fly.glide
 * Project_Name：GlideDemo
 * User：郭鹏飞
 * Date：2015/12/9
 * Email：love518420@foxmail.com
 * Description：可以得到圆角/圆形/普通 位图
 */
public class MulBitmapTransformation extends BitmapTransformation {

    public static final int TYPE_NORMAL = 0;
    public static final int TYPE_CIRCLE = 1;
    public static final int TYPE_CORNER = 2;

    // 位图类型
    private int type;
    // 圆角
    private int radius = 10;

    public MulBitmapTransformation(Context context, int type) {
        super(context);
        this.type = type;
    }

    public MulBitmapTransformation(BitmapPool bitmapPool, int type) {
        super(bitmapPool);
        this.type = type;
    }

    public void setRadius(int radius) {
        this.radius = radius;
    }

    @Override
    protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
        switch (type) {
            case TYPE_NORMAL:
                return toTransform;
            case TYPE_CIRCLE:
                return BitmapUtil.circleBitmap(toTransform);
            case TYPE_CORNER:
                return BitmapUtil.roundCorners(toTransform, radius);
            default:
                return toTransform;
        }
    }

    @Override
    public String getId() {
        return getClass().getName();
    }
}
